package com.szsfm.vehiclemanagement.manager;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * Created by zhoubigbo on 2017/11/21.
 */
public class SharePrefManager {

    private static Context mContext;

    //新消息通知开关
    public static final String SETTING_NEW_MSG_SWITCH = "SETTING_NEW_MSG_SWITCH";
    //声音通知开关
    public static final String SETTING_SOUND_SWITCH = "SETTING_SOUND_SWITCH";
    //震动开关
    public static final String SETTING_VIBRATE_SWITCH = "SETTING_VIBRATE_SWITCH";

    //======================================================================
    public static void setVibrateSwitchOn(boolean on) {
        Editor editor = getEditor(SETTING_VIBRATE_SWITCH);
        editor.putBoolean("VIBRATE_NOTICE", on);
        editor.commit();
    }

    public static boolean isVibrateSwitchOn() {
        SharedPreferences sp = getSharePref(SETTING_VIBRATE_SWITCH);
        return sp.getBoolean("VIBRATE_NOTICE", true);
    }

    //======================================================================
    public static void setSoundSwitchOn(boolean on) {
        Editor editor = getEditor(SETTING_SOUND_SWITCH);
        editor.putBoolean("SOUND_NOTICE", on);
        editor.commit();
    }

    public static boolean isSoundSwitchOn() {
        SharedPreferences sp = getSharePref(SETTING_SOUND_SWITCH);
        return sp.getBoolean("SOUND_NOTICE", true);
    }

    //======================================================================
    public static void setNewMessageSwitchOn(boolean on) {
        Editor editor = getEditor(SETTING_NEW_MSG_SWITCH);
        editor.putBoolean("NEW_MSG_NOTICE", on);
        editor.commit();
    }

    public static boolean isNewMessageSwitchOn() {
        SharedPreferences sp = getSharePref(SETTING_NEW_MSG_SWITCH);
        return sp.getBoolean("NEW_MSG_NOTICE", true);
    }

    //======================================================================
    private static SharedPreferences getSharePref(String key) {
        SharedPreferences sp = mContext.getSharedPreferences(key, Context.MODE_PRIVATE);
        return sp;
    }

    public static void setContext(Context appContext) {
        mContext = appContext;
    }

    private static Editor getEditor(String key) {
        Editor edt = mContext.getSharedPreferences(key, Context.MODE_PRIVATE).edit();
        return edt;
    }

}
